﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TPCN.DAL;

namespace TPCN.Controls
{
    public partial class uc_navigation : System.Web.UI.UserControl
    {
        private static List<DanhmucObj> source;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadDataToList();
                htmlcode.Text = GenarateHtmlCode();
            }
        }

        protected void LoadDataToList()
        {
            source = new List<DanhmucObj>();
            source = DanhmucDAL.GetByAll();
        }

        protected string GenarateHtmlCode()
        {
            string html = String.Empty;
            string homepath = VirtualPathUtility.ToAbsolute("~/Default.aspx");
            if (source.Count > 0)
            {
                html = "<ul class=\"navbar\">";
                foreach (DanhmucObj i in source)
                {
                    html += "<li><a href=\"" + homepath +"?CateID=";
                    html += i.DanhmucID + "\">";
                    html += i.Tendanhmuc.Trim();
                    html += "</a></li>";
                    html += Environment.NewLine;
                }
                html += "</ul>";
            }
            
            return html;
        }
    }
}